const path = require('path')
const mix = require('laravel-mix')
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')

mix.webpackConfig({
  output: {
    chunkFilename: `js/[id]${mix.inProduction() ? '.[chunkhash]' : ''}.js`,
    publicPath: '/lz-admin/',
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './app/admin/resources/assets'),
    },
  },
  plugins: [
    new LodashModuleReplacementPlugin({
      'collections': true,
      'paths': true,
    }),
    new CleanWebpackPlugin(['public/lz-admin'], {
      root: '',
      verbose: true,
    }),
  ],
})

mix.js('app/admin/resources/assets/main.js', 'js/app.js')
  .styles([
    'node_modules/normalize.css/normalize.css',
    'node_modules/nprogress/nprogress.css',
  ], './public/lz-admin/css/vendor.css')
  .sass('app/admin/resources/assets/styles/index.scss', 'css/index.css')
  .setPublicPath('public/lz-admin')
  .options({
    processCssUrls: false,
    extractVueStyles: true,
  })
  .setResourceRoot('/lz-admin/')
  .extract([
    'babel-polyfill',
    'vue',
    'vuex',
    'vue-router',
    'js-cookie',
    'nprogress',
    'axios',
    '@fortawesome/fontawesome-svg-core',
    '@fortawesome/free-solid-svg-icons',
    '@fortawesome/vue-fontawesome',
    'element-ui',
  ])

if (mix.inProduction()) {
  mix.version()
}
